package com.sinux.mms.service.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.sinux.mms.dao.MemberDaoI;
import com.sinux.mms.dao.RecordDaoI;
import com.sinux.mms.entity.Member;
import com.sinux.mms.entity.Record;
import com.sinux.mms.entity.Suser;
import com.sinux.mms.service.RecordServiceI;
import com.sinux.mms.util.DateTools;

/**
 * @author WangGan
 * @version 2017年6月16日 下午5:02:53 
 * 
 */
@Service
@SuppressWarnings("all")
public class RecordServiceImpl implements RecordServiceI {

	@Autowired
	private MemberDaoI memberDao;
	@Autowired
	private RecordDaoI recordDao;
	
	@Override
	public List<Record> findAllRecordList() {
		String hql="from Record";
		return recordDao.find(hql);
	}

	@Override
	public List<Record> findRecordPaging(int page, int rows) {
		String hql="from Record";
		List<Record> records=recordDao.find(hql, page, rows);
		List<Record> list=new ArrayList<Record>();
		for(Record re:records){
			String rhql="select t from Record r left join r.member t where r.id=:rid";
			Map<String, Object> params=new HashMap<String, Object>();
			params.put("rid", re.getId());
			Member me=memberDao.get(rhql);
			if (me != null ) {
				re.setTemp1(me.getName());
				re.setTemp2(me.getPhone());
				list.add(re);	
			}
			
			
		}
		return records;
	}

	@Override
	public List<Record> findRecordList(String value) {
		String hql="from Record r where (r.id like '%"+value+"%' or r.mid like '%"+value+"%') ";
		List<Record> records=recordDao.find(hql);
		return records;
	}

	@Override
	public void addMember(Record record) {
		record.setCdate(DateTools.getCurrentTime());
		recordDao.save(record);
	}

	@Override
	public void upMember(Record record) {
		// TODO Auto-generated method stub
		
	}

}
